package 并发编程02.synchronized的应用;

import java.lang.management.ManagementFactory;

public class ManyThreadReadOneVar {

    public int commonVarible;

    public synchronized void addVarible(){
        commonVarible++;
    }

    public static void main(String[] args) {
        final  ManyThreadReadOneVar mtro=new ManyThreadReadOneVar();
        for(int i=0;i<10000;i++){
            mtro.test();
        }
        while(Thread.activeCount()>2){
            Thread.yield();
        }
        System.out.println(mtro.commonVarible);
    }

    public void test(){
        Thread t1=new Thread(){
            public void run(){
                addVarible();
            }
        };
        t1.start();

    }



}
